package euler.p001_050;

import euler.MainEuler;

public class Euler048 extends MainEuler {

    /*
        The series, 1^1 + 2^2 + 3^3 + ... + 10^10 = 10405071317.

        Find the last ten digits of the series, 1^1 + 2^2 + 3^3 + ... + 1000^1000.

     */
    private static long mod = 10000000000l;

    public String resolve() {

        long suma = 0;
        for (int i = 1; i<=1000; i++) {
            suma = (pow(i)+suma)%mod;
        }

        return String.valueOf(suma);
    }

    private static long pow(int n) {
        long p = 1;

        for (int i = 0; i<n; i++) {
            if (p == 0) {
                return 0;
            }
            p = (p*n)%mod;
        }

        return p;
    }

}
